package com.neutech.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.neutech.po.User;
import com.neutech.service.UserService;
//@RestController
@Controller
@RequestMapping(value="/his")
public class UserController {
	@Autowired
	private UserService userService;
	@RequestMapping("/getUserById")
	public @ResponseBody User getUserById(Integer id) throws Exception{
		User user = userService.getUser(id);	
		return user;		
	}
	@RequestMapping(value="/updateUser",method=RequestMethod.POST)
	public @ResponseBody void updateUser() throws Exception{
		userService.updateUser();	
	}
	@RequestMapping("/deleteUser")
	public @ResponseBody  void deleteUser(Integer id) throws Exception{
		userService.deleteUser(id);		
	}
	@RequestMapping("/addUser")
	public @ResponseBody void addUser() throws Exception{
		userService.addUser();		
	}
	
	
	
	
//	@RequestMapping(value="/login",method=RequestMethod.GET)
//	public String login(Model model,@RequestParam(value="username",defaultValue="haha") String name){
//		System.out.println("欢迎"+name+"的到来!");
//		model.addAttribute("name","value");
//		return "main";
//	}
//	/*另一种方式ModelAndView*/
//	/*@RequestMapping(value="/login",method=RequestMethod.GET)
//	public ModelAndView login(Model model,@RequestParam(value="username",defaultValue="haha") String name){
//		System.out.println("欢迎"+name+"的到来!");
//		ModelAndView mv = new ModelAndView();
//		mv.addObject("key", "value");
//		mv.setViewName("main");
//		model.addAttribute("name","value");
//		return mv;
//	}*/
//	
//	@RequestMapping(value="/addUser",method=RequestMethod.POST)
//	public @ResponseBody User addUser(User user){
//		System.out.println(user.getUsername());
//		System.out.println(user.getSex());
//		return user;
//	}
//	
//	@RequestMapping("/updateUser")
//	public String updateUser(Integer id){
//		System.out.println(id);
//		return "main";
//	}
//	
//	/*数组*/
//	@RequestMapping(value="/selectUser",method=RequestMethod.POST)
//	public String selectUser(@RequestParam(value="userid",defaultValue="0") Integer[] userid){
//		for(Integer id:userid){
//			System.out.println(id);
//		}
//		return "main";
//	}
//	
//	/*集合*/
//	@RequestMapping(value="/delUser",method=RequestMethod.POST)
//	public String delUser(@RequestParam(value="namelist") List<String> namelist){
//		for(String u:namelist){
//			System.out.println(u);
//		}
//		return "main";
//	}
//	
//	/*Map形式*/
//	@RequestMapping(value="/delAllUser",method=RequestMethod.POST)
//	public String delAllUser(@RequestParam Map<String,String> nameList){
//		for(Map.Entry<String, String> set:nameList.entrySet()){
//			System.out.println(set.getKey()+":"+set.getValue());
//		}
//		return "main";
//	}
//	
//	/*前端传JSON形式*/
//	@RequestMapping(value="/delAllUserJSON",method=RequestMethod.POST)
//	public String delAllUserJSON(@RequestBody Map<String,String> nameList){
//		for(Map.Entry<String, String> set:nameList.entrySet()){
//			System.out.println(set.getKey()+":"+set.getValue());
//		}
//		return "main";
//	}
}
